﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// 给定一个包含图书的列表，每本图书有标题和出版年份。按出版年份对图书进行升序排序，并选择前 3 本图书的标题。
namespace CS_BEGINNER_TO_PROFICIENT.STD.LinqSTD
{
    public class P3
    {
        public static void Execute()
        {
            List<Book> books = new List<Book>
            {
                new Book { Title = "b", Year = 2004},
                new Book { Title = "c", Year = 2003},
                new Book { Title = "d", Year = 1923},
                new Book { Title = "e", Year = 2009},
                new Book { Title = "f", Year = 2005},
            };

            var res = books.OrderBy(b => b.Year).Take(3).Select(b => b.Title);
            foreach (var i in res)
            {
                Console.WriteLine(i);
            }
        }
    }

    public class Book
    {
        public string Title { get; set; }
        public int Year { get; set; }
    }
}
